package com.lw;

import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

/**
 * 背景
 */
@NoArgsConstructor
@Getter
public class Background {
    private BufferedImage bgImage = null;//当前场景要显示的图像
    private int sort;//记录当前是第几个场景  从1开始
    private boolean flag;//是否是最后一个场景 true是

    private List<Obstacle> obstacleList = new ArrayList<>();//存放所有障碍物

    public Background(int sort, boolean flag) {
        this.sort = sort;
        this.flag = flag;

        if(flag){
            bgImage = StaticValue.bg2;
        }else{
            bgImage = StaticValue.bg;
        }

        //判断是否是第一关
        if(sort==1){
            //绘制地面
            for (int i = 0; i < 27; i++) {
                obstacleList.add(new Obstacle(i*30,420,ObstacleType.SOIL_UPPER.getIndex(),this));
            }
            for (int i = 0; i < 27; i++) {
                for (int j = 0; j <= 120; j+=30) {
                    obstacleList.add(new Obstacle(i*30,570-j,ObstacleType.SOIL_BASE.getIndex(),this));
                }
            }

            //绘制砖块
            for (int i = 120; i <=150; i+=30) {
                obstacleList.add(new Obstacle(i,300,ObstacleType.BRICK2.getIndex(),this));
            }
            for (int i = 300; i <=570; i+=30) {
                if(i==360||i==390||i==480||i==510||i==540){
                    obstacleList.add(new Obstacle(i,300,ObstacleType.BRICK2.getIndex(),this));
                }else{
                    obstacleList.add(new Obstacle(i,300,ObstacleType.BRICK.getIndex(),this));
                }
            }
            for (int i = 420; i <=450; i+=30) {
                obstacleList.add(new Obstacle(i,240,ObstacleType.BRICK2.getIndex(),this));
            }

            //绘制水管 30*30的图片
            for (int i = 360; i <= 600; i+=25) {
                if(i==360){
                    obstacleList.add(new Obstacle(620,i,ObstacleType.PIPE1.getIndex(),this));
                    obstacleList.add(new Obstacle(645,i,ObstacleType.PIPE2.getIndex(),this));
                }else{
                    obstacleList.add(new Obstacle(620,i,ObstacleType.PIPE3.getIndex(),this));
                    obstacleList.add(new Obstacle(645,i,ObstacleType.PIPE4.getIndex(),this));
                }
            }

        }else if(sort==2){
            //如同第一关一样，只不过绘制不同的场景信息
        }else if(sort==3){

        }

    }
}
